import { instance } from '@/http/index'
import { BatchDto, SearchDto, UpdateStatusDto } from '@/types/dto'
import { LabelValue, PaginatedResponse } from '@/types/interface'
import { ApiResponseVo } from '@/types/vo'

import { RoleCriteria, RoleModalDto } from './type/dto'
import { RoleItem } from './type/vo'

/** ************** 增加( Create ) *******************/
export const createRole = (data: RoleModalDto): Promise<ApiResponseVo> => instance.post('/roles/create', data)

/** ************** 读取( Read ) *******************/
export const getRoleList = (params: SearchDto<RoleCriteria>): Promise<ApiResponseVo<PaginatedResponse<RoleItem>>> =>
  instance.post('/roles/list', params)

export const getRoleOptions = (): Promise<ApiResponseVo<LabelValue[]>> => instance.post('/roles/options')

/** ************** 修改( Update ) *******************/
export const updateRole = (data: RoleModalDto): Promise<ApiResponseVo> => instance.post('/roles/update', data)

export const updateRoleStatus = (data: UpdateStatusDto): Promise<ApiResponseVo> => instance.post('/roles/status', data)

/** ************** 删除( Delete ) *******************/
export const deleteRole = (data: BatchDto): Promise<ApiResponseVo> => instance.post('/roles/delete', data)
